home *** CD-ROM | disk | FTP | other *** search
- <?php
- ////////////////////////////////////////////////////////////////////////////////
- // <!--Copyright (c) 2005 Pure Networks Inc. All rights reserved.-->
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Build: 3.0.6121.0 (Stable)
- // $Revision: #3 $
- //
-
- function goto($newLocation)
- {
- // On Windows, the dirname($_SERVER['PHP_SELF'] can have a Windows style \ in the path.
- // For cross platform compatibility and HTTP friendliness in Browsers that don't
- // self correct this, we do a str_replace to change all instances of \ to /
- $dirName = str_replace("\\", "/", dirname($_SERVER['PHP_SELF']));
- header("location: http://" . $_SERVER['HTTP_HOST'] . $dirName . $newLocation);
- exit();
- }
-
- function gotoAbs($newLocation)
- {
- // On Windows, the dirname($_SERVER['PHP_SELF'] can have a Windows style \ in the path.
- // For cross platform compatibility and HTTP friendliness in Browsers that don't
- // self correct this, we do a str_replace to change all instances of \ to /
- header("location: http://" . $_SERVER['HTTP_HOST'] . $newLocation);
- exit();
- }
-
- function set_transfer_cookie()
- {
- // We generally call this on pages that may need to be reached via session timeout
- // or bookmarks. We call it when we realize we have no session, and then check the
- // cookie after login to ship them to the proper place.
- $sURI = $_SERVER['REQUEST_URI'];
- setcookie("transfer_url", $sURI,time()+(300),"/"); //give them 5 minutes to use the transfer url
- }
-
- function clear_transfer_cookie()
- {
- setcookie("transfer_url", "",0,"/");
- }
-
- function logoff()
- {
- log_activity("logout", "success", "");
- setcookie("transfer_url", "", time() -3600,"/");
- setcookie("browse_mode", "", time() -3600,"/");
-
- $_SESSION['user_is_logged_on'] = FALSE;
- $_SESSION['session_id'] = "";
-
- // Unset all of the session variables.
- $_SESSION = array();
-
- // Finally, destroy the session.
- session_destroy();
- }
-
-
- // Call this function after initially logging onto the system
- function logon($nmRaManager)
- {
- log_activity("logon", "success", "");
- $_SESSION['user_is_logged_on'] = TRUE;
- $_SESSION['time_last_used'] = time();
-
- // This is a useful debugging tool, not really used for anything
- $_SESSION['time_last'] = date('c');
-
- // track a hash of the initial session's IP
- $_SESSION['session_id'] = strtolower(md5(md5($_SERVER['REMOTE_ADDR'])));
-
- // set a cookie so we can bounce after browser close
- setcookie("browse_mode", "active",0,"/"); // no time = expires at browser close
-
- $iCounter = $nmRaManager->SuccessfulLoginAttempts;
- $nmRaManager->SuccessfulLoginAttempts = ($iCounter + 1);
- }
-
- // Call this function every time the user hits a page (thus updating
- // session expire time).
- function logonUpdate()
- {
- $_SESSION['time_last_used'] = time();
-
- // This is a useful debugging tool, not really used for anything
- $_SESSION['time_last'] = date('c');
-
- // set a cookie so we can bounce after browser close
- setcookie("browse_mode", "active",0,"/"); // no time = expires at browser close
- }
-
- function is_user_logged_on()
- {
- if (isset($_COOKIE['browse_mode']) and ($_COOKIE['browse_mode'] == "active"))
- {
- if (isset($_SESSION['user_is_logged_on']) and ($_SESSION['user_is_logged_on'] == TRUE))
- {
- // Also need to verify that the session hasn't expired
- // We need the 'time_last_used', if that is not set then
- // something is wrong, just bail
- if (!isset($_SESSION['time_last_used']))
- {
- logoff();
- return 0;
- }
- if (ini_get('session.cookie_lifetime') != 0)
- {
- if ((time() - $_SESSION['time_last_used']) > ini_get('session.cookie_lifetime'))
- {
- // The user session has timed out, logoff
- logoff();
- return 0;
- }
- }
- // Update the session timestamp
- logonUpdate();
- return 1;
- }
- else
- {
- return 0;
- }
- }
- else
- {
- return 0;
- }
- }
-
- function truncate_string($strString, $iCharsAllowed, $sEndChars, $sTruncSide, $bTruncateIE)
- {
- // See if we're not in IE6, if we're not, we'll truncate
- // If we're in IE6, we'll use the css text-overflow style to clip instead
- if ((!stristr($_SERVER['HTTP_USER_AGENT'], "MSIE 6.0")) or $bTruncateIE)
- {
- // Truncate the passed string for non IE6 browsers (or IE as well if $bTruncateIE is true)
- if (strlen($strString) > $iCharsAllowed)
- {
- if ($sTruncSide == "left")
- {
- // reverse it so when we substr to the right, we're actually taking
- // off the left side of the "real" string
- $strString = strrev($strString);
- }
- $strString = substr($strString, 0, $iCharsAllowed);
- $strString .=$sEndChars;
- if ($sTruncSide == "left")
- {
- // reverse it back again so that the "real" string reads properly
- $strString = strrev($strString);
- }
- }
- }
- return $strString;
- }
-
- function goto_logged_in_url()
- {
- //see if we need to ship them elsewhere due to bookmark, etc...
- if (isset($_COOKIE['transfer_url']))
- {
- header("location: http://" . $_SERVER['HTTP_HOST'] . $_COOKIE['transfer_url']);
- exit();
- }
- else
- {
- //We've succeeded, let's go!
- gotoAbs('/folders/private');
- exit();
- }
- }
-
- function log_activity($sAction, $sResult, $sMessage)
- {
- // format of the log is:
- // [DATE(added by PHP)] Remote IP:PHP Page:Action:Result:[opt]error message/exception message/additional text
- // Result is one of: success, failure, error, exception, info
- error_log("[" . date("D M d H:i:s Y") . "] " . $_SERVER['PHP_SELF'] . ":" . $sAction . ":" . $sResult . ":" . $sMessage, 0);
- }
-
- function getSerializedProperty ($sVarName)
- {
- $sFile = session_save_path() . "/" . $sVarName;
- if (file_exists($sFile))
- {
- $handle = fopen($sFile, 'rb');
- // Read content from our opened file.
- $sContents = fread($handle, filesize($sFile));
- fclose($handle);
-
- if ($sContents == "")
- {
- log_activity("get serialized property for " . $sVarName, "failure", return_error_text(115, "", $arErrors));
- return false;
- }
- else
- {
- $objVarObject = unserialize($sContents);
- log_activity("get serialized property for " . $sVarName, "success", serialize($objVarObject));
- return $objVarObject;
- }
- }
- else
- {
- return false;
- }
- }
-
- function setSerializedProperty ($sVarName, $objVarObject)
- {
- $sFile = session_save_path() . "/" . $sVarName;
- // there were issues with PHP only writing to the size of the previous file in some cases, let's biff it and start afresh.
- unlink($sFile);
- $handle = fopen($sFile, wb);
- // Write content to our newly opened file.
- if (fwrite($handle, serialize($objVarObject)) === FALSE)
- {
- log_activity("set serialized property for " . $sVarName, "failure", return_error_text(115, "", $arErrors));
- return false;
- }
- fclose($handle);
- log_activity("set serialized property for " . $sVarName, "success", serialize($objVarObject));
- return true;
- }
-
- function deleteSerializedProperty ($sVarName)
- {
- $sFile = session_save_path() . "/" . $sVarName;
- // there were issues with PHP only writing to the size of the previous file in some cases, let's biff it and start afresh.
- unlink($sFile);
- fclose($handle);
- log_activity("delete serialized property for " . $sVarName, "success", serialize($objVarObject));
- return true;
- }
-
- ///////////////////////////////////////////////////
- // Determines if string is valid (non empty/non null)
- ///////////////////////////////////////////////////
- function isValidString ($string)
- {
- $bReturn = false;
- if (isset($string) && $string != null && $string != "")
- {
- $bReturn = true;
- }
- return $bReturn;
- }
-
- ///////////////////////////////////////////////////
- // return's page title -
- // uses welcome headline OR product name as base, with other bits -
- // folder and/or file name; action (upload/slideshow); etc...
- ///////////////////////////////////////////////////
- function returnPageTitle($sIntroHeadline, $sProductNameInformal, $nmSharedPlace, $sPath, $fileName)
- {
- $sPageTitle = "";
- $sSiteTitle = "";
- if (isValidString($sIntroHeadline))
- {
- $sSiteTitle = $sIntroHeadline;
- }
- else
- {
- $sSiteTitle = $sProductNameInformal;
- }
-
- // if we have multiple slashes, we've done a rewrite and need to chop off all the un-needed cruft,
- // otherwise, we use the .php as the determiner for where we are.
- if (strripos($_SERVER['PHP_SELF'], "/") > 0 )
- {
- $sSelf = strrev(strrchr(strrev(substr($_SERVER['PHP_SELF'],1)), "/"));
- }
- else
- {
- $sSelf = $_SERVER['PHP_SELF'];
- }
-
- switch ($sSelf)
- {
- case "folders/":
- case "/places.php":
- $sPageTitle = $sSiteTitle;
- break;
- case "folderview/":
- case "/shareview.php":
- $sPageTitle = $sSiteTitle . " - " . getFolderName($nmSharedPlace, $sPath);
- break;
- case "fileview/":
- case "/image.php":
- $sPageTitle = $sSiteTitle . " - " . getFolderName($nmSharedPlace, $sPath) . " - " . $fileName;
- break;
- case "slideshow/":
- case "/slideshow.php":
- $sPageTitle = "Slideshow - " . $sSiteTitle . " - " . getFolderName($nmSharedPlace, $sPath) ;
- break;
- case "/uploadform.php":
- $sPageTitle = "Upload - " . $sSiteTitle;
- break;
- case "/upload.php":
- $sPageTitle = $sSiteTitle . " - Upload Complete";
- break;
- case "/login":
- case "/login.php":
- $sPageTitle = "Sign In To: " . $sSiteTitle;
- break;
- case "/help":
- case "help/":
- case "/login.php":
- $sPageTitle = $sSiteTitle . " - Help";
- break;
- case "error/":
- case "/error.php":
- $sPageTitle = $sSiteTitle . " - Error!";
- break;
- case "preferences/":
- $sPageTitle = $sSiteTitle . " - Preferences";
- break;
- default:
- $sPageTitle = $sSiteTitle;
- break;
- }
- return $sPageTitle;
- }
-
- function urlEncodeString($string)
- {
- // | and : are illegal character vlaues for Windows filenames,
- // so we can use them as a custom encode/decode mechanism
- $sReturn = $string;
- $sReturn = str_replace("\\", "*", $sReturn);
- // encoding
- $sReturn = str_replace("%", "%25", $sReturn);
- $sReturn = str_replace("'", "%27", $sReturn);
- $sReturn = str_replace("+", "%252B", $sReturn);
- $sReturn = str_replace(" ", "%20", $sReturn);
- $sReturn = str_replace("&", "%2526", $sReturn);
- $sReturn = str_replace("#", "%23", $sReturn);
- $sReturn = str_replace("{", "%7B", $sReturn);
- $sReturn = str_replace("}", "%7D", $sReturn);
- return $sReturn;
- }
-
- function urlDecodeString($string)
- {
- // | and : are illegal character vlaues for Windows filenames,
- // so we can use them as a custom encode/decode mechanism
- $sReturn = $string;
- $sReturn = str_replace("|", "\\", $sReturn); // no longer used, but here for legacy support of bookmarks from when it was used.
- $sReturn = str_replace("*", "\\", $sReturn);
- // decoding
- $sReturn = str_replace("%25", "%", $sReturn);
- $sReturn = str_replace("%27", "'", $sReturn);
- $sReturn = str_replace("%2B", "+", $sReturn);
- $sReturn = str_replace("\\'", "'", $sReturn);
- $sReturn = str_replace("%20", " ", $sReturn);
- $sReturn = str_replace("%26", "&", $sReturn);
- $sReturn = str_replace("%23", "#", $sReturn);
- $sReturn = str_replace("%7B", "{", $sReturn);
- $sReturn = str_replace("%7D", "}", $sReturn);
- return $sReturn;
- }
-
- ///////////////////////////////////////////////////
- // Converts bytes to a human readable string
- // @param int $bytes Number of bytes
- // @param int $precision Number of decimal places to include in return string
- // @return string formatted string rounded to $precision
- ///////////////////////////////////////////////////
- function bytesToHumanReadableUsage($bytes, $precision = 2)
- {
- if (!is_numeric($bytes) || $bytes < 0)
- {
- return null;
- }
- for ($level = 0; ($bytes >= 1024) && ($level < 6); $level++)
- {
- $bytes /= 1024;
- }
- switch ($level)
- {
- case 0:
- $suffix = 'Bytes';
- break;
- case 1:
- $suffix = 'KB';
- break;
- case 2:
- $suffix = 'MB';
- break;
- case 3:
- $suffix = 'GB';
- break;
- case 4:
- $suffix = 'TB';
- break;
- case 5:
- $suffix = 'EB';
- break;
- default:
- $suffix = '';
- break;
- }
- return round($bytes, $precision) . ' ' . $suffix;
- }
-
- ///////////////////////////////////////////////////
- // let's define the browser type for code branch logic
- ///////////////////////////////////////////////////
- $btBrowserType = "default";
- $sUserAgent = strtolower(($_SERVER['HTTP_USER_AGENT']));
- if (stristr($sUserAgent,"mac_powerpc") AND stristr($sUserAgent, "msie 5"))
- {
- $btBrowserType = "macosxie";
- }
- if ((stristr($sUserAgent, "windows ce;")))
- {
- $btBrowserType = "pocketpc";
- }
- if ((stristr($sUserAgent, "msie")) AND (stristr($sUserAgent, "windows")))
- {
- $btBrowserType = "ie";
- }
-
- function getSitePreferences()
- {
- global $sStyleFamily, $sStyleName;
- $aPreferences = getSerializedProperty("prefs");
- if ($aPreferences != false)
- {
- foreach ($aPreferences as $pref)
- {
- if ($pref[0] == "theme")
- {
- $StyleFamilyName = $pref[1];
- $iDividerPos = strpos($StyleFamilyName, "/");
- $sStyleFamily = substr($StyleFamilyName, 0, $iDividerPos);
- $sStyleName = substr($StyleFamilyName, ($iDividerPos + 1));
- }
- elseif(isValidString($pref[1]))
- {
- global $ObjectsPerPage, $iMidSizeWidth, $iMidSizeHeight, $iSlideshowWidth, $iSlideshowHeight, $iRefreshInterval, $bRssFeedsEnabled;
- switch ($pref[0])
- {
- case "ObjectsPerPage":
- $ObjectsPerPage = $pref[1];
- break;
- case "iMidSizeWidth":
- $iMidSizeWidth = $pref[1];
- break;
- case "iMidSizeHeight":
- $iMidSizeHeight = $pref[1];
- break;
- case "iSlideshowWidth":
- $iSlideshowWidth = $pref[1];
- break;
- case "iSlideshowHeight":
- $iSlideshowHeight = $pref[1];
- break;
- case "iRefreshInterval":
- $iRefreshInterval = $pref[1];
- break;
- case "bRssFeedsEnabled":
- switch ($pref[1])
- {
- case "on":
- $bRssFeedsEnabled = true;
- break;
- case "off":
- $bRssFeedsEnabled = false;
- break;
- }
- break;
- }
- }
- }
- }
- }
-
- function setSitePreferences($aPreferences)
- {
- $bPreferencesSet = setSerializedProperty ("prefs", $aPreferences);
- if ($bPreferencesSet)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- function convertUrlsToHyperlinks($sSearch)
- {
- $sAllowedDomains = ".com;.org;.net;.edu";
- $sReturn = "";
- $sPattern = " ";
- $arWords = split($sPattern, $sSearch);
- $arDomains = split(";",$sAllowedDomains);
-
- foreach ($arDomains as $domain)
- {
- $i = 0;
- foreach($arWords as $word)
- {
- if (strpos($word,$domain) !== false )
- {
- // we found a URL, let's see if it has http:// in it
- if (strpos($word,"http") === false )
- {
- $arWords[$i] = "<a target=\"_blank\" href=\"http://" . $word . "\">" . $word . "</a>";
- }
- else
- {
- $arWords[$i] = "<a target=\"_blank\" href=\"" . $word . "\">" . $word . "</a>";
- }
- }
- $i++;
- }
- $i++;
- }
-
- $i = 0;
- foreach($arWords as $word)
- {
- if ($i == 0)
- {
- $sReturn = $word;
- }
- else
- {
- $sReturn .= " " . $word;
- }
- $i++;
- }
-
- return $sReturn;
- }
-
- function isIpAddressPrivate($sIPAddress = "")
- {
- ////////////////////////////////////////////////////////////////////////////////
- // For the sake of determining if you are viewing the site as a private IP
- // address (instead of by domain name) we will define the following blocks as
- // private (per IANA in RFC 1597.) If you are using a private IP to access your
- // site, we can safely assume you are internal to the network it is on and will
- // need things like the feed to use the internal IP address as well.
- ////////////////////////////////////////////////////////////////////////////////
- // 10.0.0.0 - 10.255.255.255
- // 127.0.0.1 - 127.0.0.1
- // 172.16.0.0 - 172.31.255.255
- // 192.168.0.0 - 192.168.255.255
- ////////////////////////////////////////////////////////////////////////////////
-
- $lTestedIpAddress = ip2long($sIPAddress);
- $bReturn = false;
-
- $lRangeStart10Dot = ip2long("10.0");
- $lRangeEnd10Dot = ip2long("10.255.255.255");
- if ($lTestedIpAddress > $lRangeStart10Dot && $lTestedIpAddress < $lRangeEnd10Dot)
- {
- $bReturn = true;
- }
-
- $lRangeLoopback = ip2long("127.0.0.1");
- if ($lTestedIpAddress == $lRangeLoopback)
- {
- $bReturn = true;
- }
-
- $lRangeStart172Dot = ip2long("172.16.0");
- $lRangeEnd172Dot = ip2long("172.31.255.255");
- if ($lTestedIpAddress > $lRangeStart172Dot && $lTestedIpAddress < $lRangeEnd172Dot)
- {
- $bReturn = true;
- }
-
- $lRangeStart192Dot = ip2long("192.168.0");
- $lRangeEnd192Dot = ip2long("192.168.255.255");
- if ($lTestedIpAddress > $lRangeStart192Dot && $lTestedIpAddress < $lRangeEnd192Dot)
- {
- $bReturn = true;
- }
-
- return $bReturn;
- }
-
- function isPhotoFile($sFileNameOrPath)
- {
- global $sincPhotoFileExtensions;
- $bReturn = false;
- $sFileExtension = strtolower(strrchr($sFileNameOrPath, "."));
-
- if (stristr($sincPhotoFileExtensions, $sFileExtension))
- {
- $bReturn = true;
- }
-
- return $bReturn;
- }
- ?>